#include <iostream>
#include <string>
using namespace std;
string version1(const string & s1, const string & s2);
const string & version2(string & s1, const string & s2);

int main_str_quote(int argc, char const *argv[])
{
    cout << "Enter a string: ";
    string input;
    string result;
    getline(cin,input);
    result = version1(input, "***");
    cout << "Your string enhanced: " << result << endl;
    cout << "Your original string: " << input << endl;
    // result:0x7ff7b9786490
    cout << "result:" << &result << endl;

    string result2 = version2(input, "===");
    cout << "result2:" << &result2 << endl;

    return 0;
}

/*
 * 这里返回的时候会重新开辟一份内存，从而将temp拷贝到内存中，然后再从内存中拷贝到result中
 */
string version1(const string & s1, const string & s2) {
    string temp;
    temp = s2 + s1 + s2;
    // temp: 0x7ff7b9786468
    cout << "temp: " << &temp << endl;
    return temp;
}

const string & version2(string & s1, const string & s2) {
    s1 = s1 + s2;
    std::cout << "version2:" << &s1 << std::endl;
    return s1;
}


